<?php

namespace app\api\controller\v35;

use app\api\controller\v13\Auth2;
use app\common\cachemodel\zl2\AstroFortuneChange as AstroFortuneChangeModel;
use think\response\Json;

class AstroFortuneChange extends Auth2
{
    /**
     * 星运变动     首页
     * @return Json
     * @throws \Exception
     */
    public function index()
    {
        $date = input('date/s', '');
        $type = input('type/d', 1);
        if (!in_array($type, [1, 2, 3], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }
        if (!$this->user && in_array($type, [2, 3], true))
        {
            return show(config('code.login'), '前往登录');
        }
        if ($date && $date !== (date("Y-m-d", strtotime($date))))
        {
            return show(config('code.error'), '日期格式异常，请稍后再试～');
        }

        if (in_array($type, [2, 3], true) && $this->user['rid'] <= 0)
        {
            return show(406, '档案缺失');
        }

        $resData = (new AstroFortuneChangeModel())->getRecodeAstroFortuneChange($this->user['id'] ?: 0, $this->user['rid'], $date, $type);
        return show(config('code.success'), '请求成功', $resData);
    }
}
